package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.IRecruitmentDao;
import com.cn.wanxi.model.OrdbyModel;
import com.cn.wanxi.model.RecruitmentModel;
import com.cn.wanxi.util.GetSqlSession;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RecruitmentDaoImpl implements IRecruitmentDao {
    JDBC jdbc=new JDBC();
    @Override
    public List<RecruitmentModel> findAll() {
        String sql="SELECT * FROM recruitment ";
        ResultSet resultSet=jdbc.getResultSet(sql);
        List<RecruitmentModel> list=new ArrayList<>();
        try {
            while (resultSet.next()){
                RecruitmentModel model=new RecruitmentModel();
                model.setId(resultSet.getInt("id"));
                model.setIntroduction(resultSet.getString("introduction"));
                model.setWages(resultSet.getString("wages"));
                model.setAddress(resultSet.getString("address"));
                model.setPhone(resultSet.getString("phone"));
                model.setMailbox(resultSet.getString("mailbox"));
                model.setPosition(resultSet.getString("position"));
                list.add(model);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        jdbc.closeConn();
        return list;
    }

    @Override
    public int deleteById(int recruitmentId) {
        return GetSqlSession.getSqlSession().delete("com.cn.wanxi.dao.IRecruitmentDao.deleteById",recruitmentId);
    }

    @Override
    public int recruitmentAdd(RecruitmentModel recruitmentModel) {
        return GetSqlSession.getSqlSession().insert("com.cn.wanxi.dao.IRecruitmentDao.recruitmentAdd",recruitmentModel);
    }

    @Override
    public RecruitmentModel recruitmentFindById(int recruitmenIid) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.IRecruitmentDao.recruitmentFindById",recruitmenIid);
    }

    @Override
    public int recruitmentUpdate(RecruitmentModel recruitmentModel) {
        return GetSqlSession.getSqlSession().update("com.cn.wanxi.dao.IRecruitmentDao.recruitmentUpdate",recruitmentModel);
    }

    @Override
    public List<RecruitmentModel> findTh(RecruitmentModel recruitmentModel) {
        System.out.println("ORDER 就是就是"+recruitmentModel.getOrdbyModel().getOrdbywages());
        return GetSqlSession.getSqlSession().selectList("com.cn.wanxi.dao.IRecruitmentDao.findTh",recruitmentModel);
    }

    @Override
    public int getCont(RecruitmentModel recruitmentModel) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.wanxi.dao.IRecruitmentDao.getCont",recruitmentModel);
    }

    @Override
    public List<RecruitmentModel> recruitmentFind() {
        return GetSqlSession.getSqlSession().selectList("com.cn.wanxi.dao.IRecruitmentDao.recruitmentFind");
    }
}
